package com.neymar.controller;


import com.neymar.entity.Recruiter;
import com.neymar.entity.User;
import com.neymar.logEnum.ObjectionTypeEnum;
import com.neymar.service.LogService;
import com.neymar.service.RecruiterService;
import com.neymar.vo.R;
import com.neymar.vo.RecruiterVO;
import com.neymar.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 招聘者表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/recruiter")
@Api(tags = {"招聘者信息操作接口"})
public class RecruiterController {

    @Autowired
    private RecruiterService recruiterService;

    @Autowired
    private LogService logService;

    @ApiOperation("保存招聘者信息")
    @PostMapping("/save")
    public R save(@RequestBody Recruiter recruiter) {
        int flag = recruiterService.save(recruiter);
        if (flag != 0) {
            logService.save(recruiter.getUserId(), 1, 1);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("通过ID查看招聘者信息")
    @GetMapping("/find/{userId}")
    public R findRecruiter(@PathVariable("userId") String userId) {
        logService.save(userId, 1, 1);
        return R.ok(recruiterService.findInfo(userId));
    }


    @ApiOperation("通过ID查看招聘者公司Id")
    @GetMapping("/findCompanyId/{userId}")
    public R findRecruiterCompanyId(@PathVariable("userId") String userId) {
        logService.save(userId, 4, 1);
        return R.ok(recruiterService.findRecruiterCompanyId(userId));
    }

    @ApiOperation("通过ID查看招聘者详细信息")
    @GetMapping("/findRecruiter/{userId}/{operatorId}")
    public R findRecruiterInfo(@PathVariable("userId") String userId,
                               @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 1);
        return R.ok(recruiterService.findRecruiter(userId));
    }

    @ApiOperation("通过ID删除招聘者信息")
    @DeleteMapping("/delete/{userId}")
    public R deleteRecruiterById(@PathVariable("userId") String userId) {
        int flag = recruiterService.deleteRecruiterById(userId);
        if (flag != 0) {
            logService.save(userId, 2, 1);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("通过ID更新招聘者信息")
    @PutMapping("/update")
    public R updateRecruiterById(@RequestBody Recruiter recruiter) {
        int flag = recruiterService.updateRecruiterById(recruiter);
        if (flag != 0) {
            logService.save(recruiter.getUserId(), 3, 1);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("查看招聘者数量")
    @GetMapping("/showNumInfo/{operatorId}")
    public R recruiterNumber(@PathVariable("operatorId") String operatorId) {
        int flag = recruiterService.recruiterNumber();
        if (flag != 0) {
            logService.save(operatorId, 3, 1);
            return R.ok(flag);
        }
        return R.fail();
    }

    @ApiOperation("[分页查询] 查看所有的招聘者的信息")
    @GetMapping("/findRecruiters/{current}/{size}/{operatorId}")
    public R findRecruiters(@PathVariable("current") int current,
                            @PathVariable("size") int size,
                            @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 3, 1);
        return R.ok(recruiterService.findRecruiters(current, size));
    }

    @ApiOperation("[分页查询] 查看所有的招聘者的信息[包含招聘者公司的详细信息]")
    @GetMapping("/findRecruitersDetails/{current}/{size}/{operatorId}")
    public R findRecruitersDetails(@PathVariable("current") int current,
                                   @PathVariable("size") int size,
                                   @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 3, 1);
        return R.ok(recruiterService.findRecruitersDetails(current, size));
    }

}

